home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / val-num-chars.izs < prev    next >
Text File  |  2005-09-28  |  3KB  |  113 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Validation (Num. or Chars)
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>Validates an input field to make sure that only a number or character is entered. If you enter a number or a letter everything you can continue on. But, try entering another value like an exclamation point (!), an ampersand (&), or a dollar sign ($) and see what happens. It even highlights the incorrect entry field for you.   <!/DESCRIPTION> 
  7.  
  8. <!CATEGORY>Forms<!/CATEGORY>
  9.  
  10. <!SCRIPT>
  11. <!-- START OF SCRIPT -->
  12.  
  13.  
  14. <!-- HOW TO INSTALL VALIDATION (NUM. OR CHARS):
  15.  
  16.   1.  Copy code into the HEAD section of document
  17.   2.  Put last coding into the BODY section of document  -->
  18.  
  19. <!-- STEP ONE: Add code into HEAD section of document  -->
  20.  
  21. <HEAD>
  22.  
  23. <SCRIPT LANGUAGE="JavaScript">
  24.  
  25.  
  26.  
  27. <!-- Begin
  28. function validate(field) {
  29. var valid = "abcdefghijklmnopqrstuvwxyz0123456789"
  30. var ok = "yes";
  31. var temp;
  32. for (var i=0; i<field.value.length; i++) {
  33. temp = "" + field.value.substring(i, i+1);
  34. if (valid.indexOf(temp) == "-1") ok = "no";
  35. }
  36. if (ok == "no") {
  37. alert("Invalid entry!  Only characters and numbers are accepted!");
  38. field.focus();
  39. field.select();
  40.    }
  41. }
  42. //  End -->
  43. </script>
  44. </HEAD>
  45.  
  46. <!-- STEP TWO: Add code into BODY section of document  -->
  47.  
  48. <BODY>
  49.  
  50. <center>
  51. <form onSubmit="http://your-web-site-address-here.com/script.cgi">
  52. <input type=text name="entry" onBlur="validate(this)">
  53. <br>
  54. <input type=submit value="Submit Form">
  55. </form>
  56. </center>
  57.  
  58. <!-- END OF SCRIPT -->
  59. <!/SCRIPT>
  60.  
  61. <!PREVIEW>
  62. <!-- START OF SCRIPT -->
  63.  
  64.  
  65. <!-- HOW TO INSTALL VALIDATION (NUM. OR CHARS):
  66.  
  67.   1.  Copy code into the HEAD section of document
  68.   2.  Put last coding into the BODY section of document  -->
  69.  
  70. <!-- STEP ONE: Add code into HEAD section of document  -->
  71.  
  72. <HEAD>
  73.  
  74. <SCRIPT LANGUAGE="JavaScript">
  75.  
  76.  
  77.  
  78. <!-- Begin
  79. function validate(field) {
  80. var valid = "abcdefghijklmnopqrstuvwxyz0123456789"
  81. var ok = "yes";
  82. var temp;
  83. for (var i=0; i<field.value.length; i++) {
  84. temp = "" + field.value.substring(i, i+1);
  85. if (valid.indexOf(temp) == "-1") ok = "no";
  86. }
  87. if (ok == "no") {
  88. alert("Invalid entry!  Only characters and numbers are accepted!");
  89. field.focus();
  90. field.select();
  91.    }
  92. }
  93. //  End -->
  94. </script>
  95. </HEAD>
  96.  
  97. <!-- STEP TWO: Add code into BODY section of document  -->
  98.  
  99. <BODY>
  100.  
  101. <center>
  102. <form onSubmit="http://your-web-site-address-here.com/script.cgi">
  103. <input type=text name="entry" onBlur="validate(this)">
  104. <br>
  105. <input type=submit value="Submit Form">
  106. </form>
  107. </center>
  108.  
  109. <!-- END OF SCRIPT -->
  110. <!/PREVIEW>
  111.  
  112. <!RELATED>NONE<!/RELATED>
  113.